<template>
  <div>
    <FormPanel :list="topFilterList" :cols="2" :collapse="false" :labelWidth="110" :isSubmitBtn="false" />
    <FormPanel :list="bottomFilterList" :cols="4" :collapse="false" :labelWidth="110" :isSubmitBtn="false" />

    <div style="margin: 0 auto; text-align: center">
      <el-button type="primary" @click="saveDialog">保 存</el-button>
      <el-button @click="closeDialog">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';

import moment from 'moment';
import { queryRemindInfo, addRemind } from '@/api/customerRepair/customerLoss/lossRemind';
export default {
  name: 'remindModel',
  mixins: [dictionary],
  props: ['selectColumns'],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      bottomFilterList: this.createBotFilterList(),
      ownerNo: '',
      resultCode: ''
    };
  },
  mounted() {
    this.queryRemindInfos();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '车主姓名',
          fieldName: 'ownerName',
          rules: [{ required: true, message: '请输入提醒内容', trigger: 'blur' }],
          disabled: true
        },
        {
          type: 'INPUT',
          label: '上次维修时间',
          fieldName: 'lastMaintainDate',
          disabled: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          type: 'TEXT_AREA',
          label: '提醒内容',
          fieldName: 'remindContent',
          selfCols: 2,
          rows: 4,
          maxlength: 100,
          rules: [{ required: true, message: '请输入提醒内容', trigger: 'blur' }]
        },
        {
          type: 'TEXT_AREA',
          label: '客户反馈',
          fieldName: 'customerFeedback',
          selfCols: 2,
          rows: 4,
          maxlength: 100
        }
      ];
    },
    createBotFilterList() {
      return [
        {
          type: 'SELECT',
          label: '提醒方式',
          fieldName: 'remindWay',
          itemList: this.createDictList('8081')
        },
        {
          type: 'INPUT',
          label: '提醒人',
          fieldName: 'reminder',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '提醒状态',
          fieldName: 'remindStatus',
          itemList: this.createDictList('8057')
        },
        {
          type: 'SELECT',
          label: '提醒失败原因',
          fieldName: 'remindFailReason',
          itemList: this.createDictList('8069')
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          selfCols: 4,
          rows: 4,
          maxlength: 100
        }
      ];
    },

    changeHandle(val) {
      console.log(val, 'val');
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },

    async queryRemindInfos() {
      let vin = this.selectColumns[0].VIN;
      const res = await queryRemindInfo(vin);
      // console.log(res,'res')
      if (res.resultCode == 200) {
        this.topFilterList[0].initialValue = res.data.OWNER_NAME;
        this.topFilterList[1].initialValue = res.data.LAST_MAINTAIN_DATE;
        this.bottomFilterList[1].initialValue = this.selectColumns[0].REMINDER;
        this.ownerNo = res.data.OWNER_NO;
      }
    },

    saveDialog() {
      if (!this.topFilterList[2].initialValue) {
        this.$notify.error({ title: '提示信息', message: '提醒内容是必填项!' });
        return;
      }

      this.$confirm('是否确认保存?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          let vin = this.selectColumns[0].VIN;
          let obj = {
            customerFeedback: this.topFilterList[3].initialValue,
            lastMaintainDate: this.topFilterList[1].initialValue,
            ownerNo: this.ownerNo,
            remark: this.bottomFilterList[4].initialValue,
            remindContent: this.topFilterList[2].initialValue,
            remindDate: moment().format('YYYY-MM-DD'),
            remindFailReason: this.bottomFilterList[3].initialValue,
            remindStatus: this.bottomFilterList[2].initialValue,
            remindWay: this.bottomFilterList[0].initialValue,
            reminder: this.bottomFilterList[1].initialValue,
            vin: vin
          };
          // console.log(obj)
          const res = await addRemind(obj);
          // console.log(res,'res');
          if (res.resultCode == 200) {
            this.resultCode = res.resultCode;
            this.closeDialog();
          }
        })
        .catch(() => {});

      // console.log(this.topFilterList,this.bottomFilterList);
    },

    closeDialog() {
      this.$emit('closeRemindModel', this.resultCode);
    }
  }
};
</script>

<style lang="less" scoped></style>
